<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
{
    /**
     * 创建订单表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            //表属性
            $table->engine = 'InnoDB';
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            //表字段
            $table->increments('id');
            $table->string('sn',45)->comment('订单编号');
            $table->integer('goods_id')->comment('商品id');
            $table->integer('user_id')->default(0)->comment('用户id');

            $table->string('consignee',255)->comment('商品收货地址');
            $table->decimal('payed',10,0)->nullable()->comment('商品实付额');
            $table->decimal('total',10,0)->comment('商品总额');
            $table->tinyInteger('status')->default(0)->comment('商品状态,0:待支付1:待发货2:待收货3:待评价4:已关闭');

            $table->integer('num')->comment('购买数量');

            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
            $table->timestamp('deleted_at')->nullable()->comment('删除时间');
            //创建索引
            $table->unique('sn');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
